using System;
using System.Runtime.Serialization;

namespace Microsoft.WowAddonStudio.Lua.RuntimeService.Common
{
	/// <summary>
	/// Represents errors that occur during LuaRuntime execution.
	/// </summary>
	[Serializable]
	public sealed class RuntimeShellHostNotFoundException : RuntimeShellHostException
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="RuntimeShellHostNotFoundException"/> class.
		/// </summary>
		/// <param name="runtime">The <see cref="LuaRuntime"/> parameter.</param>
		public RuntimeShellHostNotFoundException(ILuaRuntime runtime)
			: this(runtime, null, AddCustomInnerException())
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="RuntimeShellHostNotFoundException"/> class.
		/// </summary>
		/// <param name="runtime">The runtime.</param>
		/// <param name="message">The message.</param>
		public RuntimeShellHostNotFoundException(ILuaRuntime runtime, string message)
			: base(runtime, message, AddCustomInnerException())
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="RuntimeShellHostNotFoundException"/> class.
		/// </summary>
		/// <param name="runtime">The runtime.</param>
		/// <param name="message">The message.</param>
		/// <param name="innerException">The inner exception.</param>
		public RuntimeShellHostNotFoundException(ILuaRuntime runtime, string message, Exception innerException)
			: base(runtime, message, innerException)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="RuntimeShellHostNotFoundException"/> class.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
		/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
		/// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception>
		/// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception>
		public RuntimeShellHostNotFoundException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
		}

		/// <summary>
		/// Adds the custom inner exception.
		/// </summary>
		/// <returns></returns>
		private static Exception AddCustomInnerException()
		{
			return new InvalidOperationException(Resources.Exception_LuaRuntimeShellHostNotFoundExceptionMessage, new NullReferenceException("IShellHost"));
		}

	}
}